package com.wzgl.core.config.plugin;


import java.util.List;

import com.jfinal.plugin.IPlugin;
import com.jfinal.plugin.activerecord.Record;
import com.wzgl.core.CacheConsts;
import com.wzgl.core.model.RecordBaseDao;
import com.wzgl.core.model.TfinishUrl;
import com.wzgl.core.utils.WZGLUtils;
import com.wzgl.core.webmagic.utils.RedisUtil;


public class RedisPluginWXZH  implements IPlugin {

	public void InitRedisPlugin(){
		RedisUtil ru = RedisUtil.getRu();
		try {
			List<Record> list = RecordBaseDao.find("tweixin_zh");
			if(list != null && list.size()>0){
				for(Record r:list){
					ru.set(r.getStr("fname"), r);
				}
			}
			
			//去除已经爬取的url
			List<TfinishUrl> tflist = TfinishUrl.dao.getAllList();
			
			if(tflist != null && tflist.size() > 0){
				for(TfinishUrl t : tflist){
					String cachename = CacheConsts.CACHE_MAGIC_GIRD_NAME;
					String name = cachename+":"+t.getFurl();
					WZGLUtils.setCache(cachename, name, t);
				}
			}
			
			System.out.println("共取出URL ： "+tflist.size());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public boolean start() {
		return true;
	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

}
